/**
*      author: Y_Yao
*      created: 2024-10-14 10:05:58
**/

#include<bits/stdc++.h>

using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
priority_queue<int,vector<int>,greater<>> heap;

void solve()
{
    int op = 0;
    cin >> op;

    if(op == 1)
    {
        int in = 0;
        cin >> in;

        heap.push(in);
    }
    else if(op == 2)
    {
        cout << heap.top() << endl;
    }
    else if(op == 3)
    {
        heap.pop();
    }

}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n = 1;
    cin >> n;
    while(n--)
    {
        solve();
    }
    return 0;
}